package zhoufu.sz.sanxiao_check.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.config.Constant;
import zhoufu.sz.sanxiao_check.inject.HasComponent;
import zhoufu.sz.sanxiao_check.inject.components.DaggerLoginComponet;
import zhoufu.sz.sanxiao_check.inject.components.LoginComponet;
import zhoufu.sz.sanxiao_check.ui.fragment.PersonCenterFragment;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/20
 */
public class MainCenterActivity extends BaseActivity implements HasComponent<LoginComponet>
{
    private LoginComponet loginComponet;

    private int action;

    @Override protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        action = getIntent().getIntExtra(Constant.MainType.ACTION_KEY, 0);
        showFragment();
    }

    private void showFragment()
    {
        FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction();
        switch (action)
        {
            case Constant.MainType.ACTION_PERSON_CENTER:
                setTitle(R.string.title_user_center);
                transaction.replace(R.id.main_fram, new PersonCenterFragment());
                break;
        }
        transaction.commitAllowingStateLoss();
    }

    @Override protected void initInject()
    {
        loginComponet = DaggerLoginComponet.builder().activityModule(getActivityModule())
                .appComponent(getAppComponent()).build();
    }

    @Override protected int setIndividualId()
    {
        return R.layout.layout_frame;
    }

    @Override public LoginComponet getComponent()
    {
        return loginComponet;
    }
}
